<?php
namespace app\admin\controller\order;

use app\admin\service\OrderService;
use app\common\model\SystemOrder;
use library\Controller;
use think\Db;
use think\Request;
use library\File;

/**
 * 制作订单
 * Class Make
 * @package app\admin\controller\order
 */
class Make extends Controller
{
     /**
     * 指定数据表
     * @var string
     */
    protected $table = 'SystemOrder';	
	
    /**
     * 订单列表
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {    	
        $this->title = '制作订单';
        $this->product_class_op = assemble_op([''=>'-- 全部产品分类 --'], get_all_product_class());
        $this->shop_op = assemble_op([''=>'-- 全部店铺 --'], get_all_shop()); 
        $this->is_print_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::IS_PRINT);    
        $this->painter_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::PAINTER); 
        $this->make_status_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::MAKE_STATUS);
        $this->detection_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::DETECTION);
        $this->pack_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::PACK);
        $this->delivery_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::DELIVERY);
        $this->delivery_click_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::DELIVERY_CLICK);
        $this->loss_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::LOSS);
        $this->order_sort_op = assemble_op([''=>'-- 全部状态 --'], ['1'=>'正序','2'=>'倒序']);
        $this->urgent_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::URGENT);
        $this->print_name_op = assemble_op([''=>'-- 全部人员 --'],get_all_options('print_name'));
        $this->maker_name_op = assemble_op([''=>'-- 全部人员 --'], get_all_options('maker_name'));
        $this->pack_name_op = assemble_op([''=>'-- 全部人员 --'], get_all_options('pack_name'));
        $this->delivery_name_op = assemble_op([''=>'-- 全部人员 --'], get_all_options('delivery_name'));
        $this->print_label_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::PRINT_LABEL);
        $this->clothing_op = assemble_op([''=>'-- 全部状态 --'], get_all_options('clothing'));
        $this->clothing_color_op = assemble_op([''=>'-- 全部状态 --'], get_all_options('clothing_color'));
        $this->clothing_size_op = assemble_op([''=>'-- 全部状态 --'], get_all_options('clothing_size'));
        $this->reissue_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::REISSUE);
        $this->is_chest_pic_op = assemble_op([''=>'-- 全部状态 --'], ['1'=>'有','2'=>'没有']);
        $this->is_sleeve_pic_op = assemble_op([''=>'-- 全部状态 --'], ['1'=>'有','2'=>'没有']);
        $this->painter_name_op = assemble_op([''=>'-- 全部人员 --'], get_all_options('painter_name'));
        $this->is_sendemail_op = assemble_op([''=>'-- 全部状态 --'], SystemOrder::IS_SENDEAMIL);
        $this->receiving_country_op = assemble_op([''=>'-- 全部国家 --'], get_all_options('receiving_country'));
        
        $where = [];       
        $where[] = ['is_deleted','eq',0];
        $where[] = ['status','in',[1,3]];  
        $status = $this->request->get('status'); 
        if($status){
        	$where[] = ['status','eq',$status];    
        }   	
        $overdue_status = $this->request->get('overdue_status'); 
        if($overdue_status){
        	$where[] = ['overdue_status','eq',$overdue_status];   
        } 
        $checkpic_status = $this->request->get('checkpic_status'); 
        if($checkpic_status){
        	if($checkpic_status == 3){
        		$where[] = ['checkpic_status','in',[3,4]];
        	}else{
        		$where[] = ['checkpic_status','eq',$checkpic_status];
        	}      	    
        }
        
        //制版标记
        $print_mark = $this->request->get('print_mark');       
        if(trim($print_mark) != ""){
        	$where[] = ['print_mark','eq',$print_mark];
        }
        	 
        $sort = 'id desc';
        $order_sort = $this->request->get('order_sort');
        if($order_sort){
        	if($order_sort == 1){
        		$sort = 'create_order_at asc';
        	}else{
        		$sort = 'create_order_at desc';
        	}
        }
        
        
        $product_class = $this->request->get('product_class');
        if($product_class){
        	$products = Db::name('system_product')->where(['product_class'=>$product_class])->order('sort desc,id asc')->column('name','id');
        	$this->product_op = assemble_op([''=>'-- 全部产品 --'], $products);
        }else{
        	$this->product_op = assemble_op([''=>'-- 全部产品 --'], get_all_product());
        }
        
        $is_chest_pic = $this->request->get('is_chest_pic');
        if($is_chest_pic){
        	if($is_chest_pic == 1){
	        	$where[] = ['chest_pic','neq',''];
	        }else{
	        	$where[] = ['chest_pic','eq',''];
	        }
        }
        $is_sleeve_pic = $this->request->get('is_sleeve_pic');
        if($is_sleeve_pic){
        	if($is_sleeve_pic == 1){
	        	$where[] = ['sleeve_pic','neq',''];
	        }else{
	        	$where[] = ['sleeve_pic','eq',''];
	        }
        }
        
        //即将逾期的数量
        $this->overdue_warning_soon = $this->_query($this->table)->where([['is_deleted','eq',0],['overdue_status','eq',2],['status','in',[1,3]]])->total();
        //已逾期的数量
        $this->overdue_soon = $this->_query($this->table)->where([['is_deleted','eq',0],['overdue_status','eq',3],['status','in',[1,3]]])->total();
        
        //核对图预警的数量
        $this->checkpic_warning_soon = $this->_query($this->table)->where([['is_deleted','eq',0],['checkpic_status','in',[3,4]],['status','in',[1,3]]])->total();
        //发邮件预警的数量
        $this->sendemail_soon = $this->_query($this->table)->where([['is_deleted','eq',0],['checkpic_status','eq',5],['status','in',[1,3]]])->total();
	
		$query = $this->_query($this->table)->like('code')->equal('product_class,product_id,shop_id,is_print,painter,make_status,detection,pack,delivery,delivery_click,loss,urgent,maker_name,delivery_name,print_label,print_name,clothing,clothing_color,clothing_size,reissue,screenshot,painter_name,pack_name,is_sendemail,receiving_country');
		$query->where($where)->order($sort)->dateSimpleBetween('pack_at,create_order_at,make_end_at,arrange_at,make_plan_at,print_end_at,check_at,delivery_real_at,send_painter_at,sendemail_at')->dateBetween('create_at,update_at')->page();		
    }
    
    
    /**
     * 列表数据处理
     * @auth true
     * @param array $data
     * @throws \Exception
     */
    protected function _index_page_filter(&$data)
    {
    	foreach($data as $vo){
    		$ids[] = $vo['id'];
    	}
		if(!empty($ids) && $ids){
			$shops = get_all_shop();
	        foreach ($data as &$vo) { 
	        	$vo['status_cn'] = SystemOrder::STATUS[$vo['status']];      	
	        	$vo['shop_name'] = $shops[$vo['shop_id']];
	        	$vo['clothing_cn'] = $vo['clothing'] ? get_all_options('clothing')[$vo['clothing']] : '';
	        	$vo['clothing_color_cn'] = $vo['clothing_color'] ? get_all_options('clothing_color')[$vo['clothing_color']] : '';
	        	$vo['clothing_size_cn'] = $vo['clothing_size'] ? get_all_options('clothing_size')[$vo['clothing_size']] : '';
	        	$vo['make_status_cn'] = SystemOrder::MAKE_STATUS[$vo['make_status']];
	        	$vo['maker_name_cn'] = $vo['maker_name'] ? get_all_options('maker_name')[$vo['maker_name']] : '';
	        	$vo['pack_cn'] = SystemOrder::PACK[$vo['pack']];
	        	$vo['delivery_cn'] = SystemOrder::DELIVERY[$vo['delivery']];
				$vo['neckline_cn'] = $vo['neckline'] ? get_all_options('neckline')[$vo['neckline']] : '';
				$vo['chest_line_color_cn'] = $vo['chest_line_color'] ? get_all_options('chest_line_color')[$vo['chest_line_color']] : '';
				$vo['sleeve_cn'] = $vo['sleeve'] ? get_all_options('sleeve')[$vo['sleeve']] : '';
				$vo['sleeve_line_color_cn'] = $vo['sleeve_line_color'] ? get_all_options('sleeve_line_color')[$vo['sleeve_line_color']] : '';
				$vo['claw_color_cn'] = $vo['claw_color'] ? get_all_options('claw_color')[$vo['claw_color']] : '';
				$vo['heart_color_cn'] = $vo['heart_color'] ? get_all_options('heart_color')[$vo['heart_color']] : '';
	        }
		}		
    }
    
    /**
     * 根据产品ID获取产品内容
     */
    public function get_product()
	{
		$product_id = $this->request->param('product_id');
		if(empty($product_id) || !$product_id){
			$this->error('参数错误');
		}
		$product = Db::name('system_product')->where(['is_deleted'=>0,'id'=>$product_id])->find();
		if($product){
			$this->success('获取成功',$product['content']);
		}else{
			$this->error('未找到产品');
		}
	}
    
    
    /**
     * 表单数据处理
     * @param array $data
     * @auth true
     */
    protected function _form_filter(array &$data)
    {
        if ($this->request->isPost()) { 	
            $where = [['code', 'eq', $data['code']]];
            if (!empty($data['id'])) $where[] = ['id ', 'neq', $data['id']];
            if (Db::name($this->table)->where($where)->count() > 0) {
                $this->error('订单已存在，请更改订单号');
            }	
            
            //制版分配权限
            $user_id = intval(session('admin_user.id'));
            if($user_id != '10000'){
            	if($data['is_print'] == 2){
            		if (!empty($data['id'])){            			
            			$print_name = Db::name($this->table)->where(['id'=>$data['id']])->value('print_name');
            			if($data['print_name'] != 1){
            				if($data['print_name'] != $print_name){
            					$this->error('暂无制版分配权限');
            				}
            			}
		            }else{
		            	if($data['print_name'] != 1){
		    				$this->error('暂无制版分配权限');
		    			}  			
		            }
            	}
            }
            
            $domain = get_host_name();
            $up_url = $domain.'/upload/';
           
            $cos_domain = strtolower(sysconf('storage_cos_is_https')).'://'.sysconf('storage_cos_domain');
	        
            if(strpos($data['content'],$up_url) !== false || strpos($data['content'],$cos_domain) !== false){
            	if(strpos($data['content'],$up_url) && strpos($data['content'],$cos_domain)){
            		$local = newstripos($data['content'],$up_url,1);
            		$cos = newstripos($data['content'],$cos_domain,1);
        			$img_url = $local < $cos ? $up_url : $cos_domain;
            	}else{
            		$img_url = strpos($data['content'],$up_url) ? $up_url : $cos_domain;
            	}            	
            	if((strpos($data['content'],'.jpg') !== false) || (strpos($data['content'],'.png') !== false)){
            		$a = newstripos($data['content'],$img_url,1);
            		$b = newstripos($data['content'],'.jpg',1);
            		$c = newstripos($data['content'],'.png',1);
            		if($b && $c){
            			if($b > $c){
            				$e = $c + 4 - $a;
            			}else{
            				$e = $b + 4 - $a;
            			}
            		}else{
            			if($b){
            				$e = $b + 4 - $a;
            			}
            			if($c){
            				$e = $c + 4 - $a;
            			}
            		}
            		            		
            		$custom_first_pic = substr($data['content'],$a,$e);
            		         		 
            		$data['custom_first_pic'] = $custom_first_pic;           		
            	}else{           		 
            		$data['custom_first_pic'] = '';
            	}   
            }else{
            	$data['custom_first_pic'] = '';
            }
            
            
            //制作情况          
            if(in_array($data['make_status'],[2,4])){
            	if($data['make_status'] == 2){
            		$data['make_plan_name'] = $data['make_plan_at'] ='';
            	}else{
            		$data['maker_name'] = $data['make_end_at'] = '';
            	}
            }else{
            	$data['maker_name'] = $data['make_end_at'] = $data['make_plan_name'] = $data['make_plan_at'] ='';
            }	
            
            
            //产品分类
            $product = Db::name('system_product')->where(['id'=>$data['product_id']])->field('id,name,product_class')->find();
            $data['product_class'] = $product['product_class'];	     
            
             //检查逾期
            $today = date('Y-m-d',time());
            $product_class = Db::name('system_product_class')->where(['id'=>$data['product_class']])->find();
            if($product_class && $product_class['overdue_day']){
            	//逾期预警时间
	            $overdue_warning_at = after_days($data['create_order_at'],$product_class['overdue_warning_day']);
	            //逾期时间
	            $overdue_at = after_days($data['create_order_at'],$product_class['overdue_day']);
	           
	            if($data['delivery'] == 1){
	            	if(strtotime($today) < strtotime($overdue_warning_at)){
	            		$data['overdue_status'] = 1;
	            	}elseif((strtotime($today) >= strtotime($overdue_warning_at)) && (strtotime($today) < strtotime($overdue_at))){
	            		$data['overdue_status'] = 2;
	            	}elseif(strtotime($today) >= strtotime($overdue_at)){
	            		$data['overdue_status'] = 3;
	            	}
	            }else{
	            	$data['overdue_status'] = 4;
	            }
	            $data['overdue_warning_at'] = $overdue_warning_at;
	            $data['overdue_at'] = $overdue_at;
            }  
            
            if($product_class && $product_class['check_warning_day']){           
	            if($data['delivery'] == 1 && $data['is_print'] == 1){           	
	            	if($data['check_at']){
	            		//核对图预警时间
	            		$check_warning_at = after_days($data['check_at'],$product_class['check_warning_day']);
	            		if(strtotime($today) < strtotime($overdue_warning_at)){
	            			$data['checkpic_status'] = 2;
	            		}else{
	            			$data['checkpic_status'] = 3;
	            		}
	            		$data['checkpic_warning_at'] = $check_warning_at;
	            	}
	            	if($data['is_sendemail'] == 2){
	            		//发邮件预警时间
	            		$email_warning_at = after_days($data['sendemail_at'],$product_class['email_warning_day']);
	            		if(strtotime($today) < strtotime($email_warning_at)){
	            			$data['checkpic_status'] = 4;
	            		}else{
	            			$data['checkpic_status'] = 5;
	            		}
	            		$data['email_warning_at'] = $email_warning_at;
	            	}	    
	            }else{
	            	$data['checkpic_status'] = 6;
	            }	            
            }  
			
        }else{
        	$this->status = SystemOrder::STATUS;
        	$this->painter = SystemOrder::PAINTER;
        	$this->kefu_exchange = SystemOrder::KEFU_EXCHANGE;
        	$this->is_print = SystemOrder::IS_PRINT;
        	$this->make_status = SystemOrder::MAKE_STATUS;
        	$this->detection = SystemOrder::DETECTION;
        	$this->pack = SystemOrder::PACK;
        	$this->delivery = SystemOrder::DELIVERY;
        	$this->delivery_click = SystemOrder::DELIVERY_CLICK;
        	$this->loss = SystemOrder::LOSS;
        	$this->is_ps = SystemOrder::IS_PS;
        	$this->custom_pic = SystemOrder::CUSTOM_PIC;
        	$this->is_sendemail = SystemOrder::IS_SENDEAMIL;
        	$this->urgent = SystemOrder::URGENT;      	        	
        	$this->print_label = SystemOrder::PRINT_LABEL;       	
        	$this->reissue = SystemOrder::REISSUE;        	       	     	
			if(!empty($data['id'])){
				$this->shop = get_all_shop();
				$this->product = get_all_product();
				$this->product_class = get_all_product_class();
				$this->receiving_country = get_all_options('receiving_country');
				$this->organizer = get_all_options('organizer');
				$this->clothing = get_all_options('clothing');
				$this->clothing_color = get_all_options('clothing_color');
				$this->clothing_size = get_all_options('clothing_size');
				$this->neckline = get_all_options('neckline');
				$this->chest_line_color = get_all_options('chest_line_color');
				$this->sleeve = get_all_options('sleeve');
				$this->sleeve_line_color = get_all_options('sleeve_line_color');
				$this->heart_color = get_all_options('heart_color');
				$this->claw_color = get_all_options('claw_color');
				$this->painter_name = get_all_options('painter_name');
				$this->print_name = get_all_options('print_name');
				$this->make_plan_name = get_all_options('make_plan_name');
				$this->detection_name = get_all_options('detection_name');
				$this->pack_name = get_all_options('pack_name');
				$this->delivery_name = get_all_options('delivery_name');
				$this->maker_name = get_all_options('maker_name');
			}else{
				$this->shop = get_normal_shop();
				$this->product = get_normal_product();
				$this->product_class = get_normal_product_class();
				$this->receiving_country = get_all_options('receiving_country');
				$this->organizer = get_normal_options('organizer');
				$this->clothing = get_normal_options('clothing');
				$this->clothing_color = get_normal_options('clothing_color');
				$this->clothing_size = get_normal_options('clothing_size');
				$this->neckline = get_normal_options('neckline');
				$this->chest_line_color = get_normal_options('chest_line_color');
				$this->sleeve = get_normal_options('sleeve');
				$this->sleeve_line_color = get_normal_options('sleeve_line_color');
				$this->heart_color = get_normal_options('heart_color');
				$this->claw_color = get_normal_options('claw_color');
				$this->painter_name = get_normal_options('painter_name');
				$this->print_name = get_normal_options('print_name');
				$this->make_plan_name = get_normal_options('make_plan_name');
				$this->detection_name = get_normal_options('detection_name');
				$this->pack_name = get_normal_options('pack_name');
				$this->delivery_name = get_normal_options('delivery_name');
				$this->maker_name = get_normal_options('maker_name');
			}
        	if($data){
        		$this->oplog = readoplog($data['id'],$this->table);
        	}     	
        }
    }
    
    
    
    /**
     * 根据产品分类获取下属产品列表
     */
    public function get_product_list()
	{
		$product_class = $this->request->param('product_class');
		if(empty($product_class) || !$product_class){
			$products = Db::name('system_product')->order('sort desc,id asc')->field('id,name')->select();
		}else{
			$products = Db::name('system_product')->where(['product_class'=>$product_class])->order('sort desc,id asc')->field('id,name')->select();
		}		
		if($products){
			$this->success('获取成功',$products);
		}else{
			$this->error('未找到产品');
		}
	}
	
	
	/**
     * 添加订单
     * @auth true
     */
    public function add()
    {
    	$this->title = '添加订单';
    	$data = [];
    	if($this->request->isPost()){
    		$data = $this->request->post();
    		trim_array($data);        	
    		if(empty($data['id'])){
    			
	            
        	}		 
        	
    	}
    	
        $this->_form($this->table, 'f_form','',[],$data);
    }
    
    
    /**
     * 表单数据后置处理
     * @param number $id
     * @auth true
     */
    protected function _add_form_result($id)
    {
		$info = Db::name($this->table)->where(['id'=>$id])->find();
		if($info){		
			sysoplog('制作订单', '新增'.$info['code'].'成功');
			operatelog($info['id'],$this->table,'进行了新增');
			$this->success('保存成功');
		}
    }
	

    /**
     * 编辑订单
     * @auth true
     */
    public function edit()
    {  	
    	$this->title = '编辑订单';
        $data = [];
    	if($this->request->isPost()){
    		$data = $this->request->post();
    		trim_array($data);          		    			
    	}  	
        $this->_form($this->table, 'f_form','',[],$data);
    }
    
    
    /**
     * 表单数据后置处理
     * @param number $id
     * @auth true
     */
    protected function _edit_form_result($id,$data)
    {
		$info = Db::name($this->table)->where(['id'=>$id])->find();
		if($info){
			sysoplog('制作订单', '编辑'.$info['code'].'成功');
			operatelog($info['id'],$this->table,'进行了编辑');
			$this->success('保存成功');	
		}
    }
    
       
    /**
     * 查看订单
     * @auth true
     */
    public function browse()
    {  	
    	$this->title = '查看订单'; 	
    	$this->_form($this->table, 'f_browse');   	 	      
    }
    
    
    /**
     * 制作情况
     * @auth true
     */
    public function make()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
    		
			$ids = explode(',',$data['ids']);
			if($data['screenshot']){
				Db::name($this->table)->where(['id'=>$ids])->update(['make_status'=>$data['make_status'],'maker_name'=>$data['maker_name'],'make_end_at'=>$data['make_end_at'],'make_plan_name'=>$data['make_plan_name'],'make_plan_at'=>$data['make_plan_at'],'screenshot'=>$data['screenshot']]);
			}else{
				Db::name($this->table)->where(['id'=>$ids])->update(['make_status'=>$data['make_status'],'maker_name'=>$data['maker_name'],'make_end_at'=>$data['make_end_at'],'make_plan_name'=>$data['make_plan_name'],'make_plan_at'=>$data['make_plan_at']]);
			}			
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->make_status = SystemOrder::MAKE_STATUS;
    		$this->maker_name = get_normal_options('maker_name');
    		$this->make_plan_name = get_normal_options('make_plan_name');
    	}  		
    	$this->fetch('make');   	 	      
    }
    
    
    /**
     * 发货状态
     * @auth true
     */
    public function delivery()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			$ids = explode(',',$data['ids']);
			if($data['delivery'] == 2){
				Db::name($this->table)->where(['id'=>$ids])->update(['delivery'=>$data['delivery'],'delivery_name'=>$data['delivery_name'],'delivery_real_at'=>$data['delivery_real_at'],'overdue_status'=>4,'checkpic_status'=>6]);
			}else{
				Db::name($this->table)->where(['id'=>$ids])->update(['delivery'=>$data['delivery'],'delivery_name'=>$data['delivery_name'],'delivery_real_at'=>$data['delivery_real_at']]);
			}
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->delivery = SystemOrder::DELIVERY;
    		$this->delivery_name = get_normal_options('delivery_name');
    	}  		
    	$this->fetch('delivery');   	 	      
    }
    
    
    /**
     * 打印标签
     * @auth true
     */
    public function label()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			$ids = explode(',',$data['ids']);
			Db::name($this->table)->where(['id'=>$ids])->update(['print_label'=>$data['print_label']]);
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->print_label = SystemOrder::PRINT_LABEL;
    	}  		
    	$this->fetch('label');   	 	      
    }
    
    /**
     * 质检状态
     * @auth true
     */
    public function detection()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			$ids = explode(',',$data['ids']);
			Db::name($this->table)->where(['id'=>$ids])->update(['detection'=>$data['detection'],'detection_name'=>$data['detection_name'],'detection_at'=>$data['detection_at']]);
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->detection = SystemOrder::DETECTION;
    		$this->detection_name = get_normal_options('detection_name');
    	}  		
    	$this->fetch('detection');   	 	      
    }
    
    
    /**
     * 打包状态
     * @auth true
     */
    public function pack()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			$ids = explode(',',$data['ids']);
			Db::name($this->table)->where(['id'=>$ids])->update(['pack'=>$data['pack'],'pack_name'=>$data['pack_name'],'pack_at'=>$data['pack_at']]);
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->pack = SystemOrder::PACK;
    		$this->pack_name = get_normal_options('pack_name');
    	}  		
    	$this->fetch('pack');   	 	      
    }
    
    
    /**
     * 整理日期
     * @auth true
     */
    public function arrange()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			$ids = explode(',',$data['ids']);
			Db::name($this->table)->where(['id'=>$ids])->update(['arrange_at'=>$data['arrange_at']]);
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    	}  		
    	$this->fetch('arrange');   	 	      
    }
    
    
    
    /**
     * 制作排单标记
     * @auth true
     */
    public function screenshot()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			$ids = explode(',',$data['ids']);
			Db::name($this->table)->where(['id'=>$ids])->update(['screenshot'=>$data['screenshot']]);
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    	}  		
    	$this->fetch('screenshot');   	 	      
    }
    
    
    /**
     * 制版状态批处理
     * @auth true
     */
    public function batch_print()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
//  		$user_id = intval(session('admin_user.id'));
//  		if(!in_array($user_id,[10000,10082,10091,10092])){
//  			if($data['is_print'] == 2){
//  				$this->error('暂无制版分配权限');
//  			}
//  		}
			$ids = explode(',',$data['ids']);
			if(in_array($data['is_print'],[2,3])){
				Db::name($this->table)->where(['id'=>$ids])->update(['is_print'=>$data['is_print'],'print_name'=>$data['print_name'],'print_end_at'=>$data['print_end_at'],'print_mark'=>$data['print_mark'],'checkpic_status'=>6]);
			}else{
				Db::name($this->table)->where(['id'=>$ids])->update(['is_print'=>$data['is_print'],'print_name'=>$data['print_name'],'print_end_at'=>$data['print_end_at'],'print_mark'=>$data['print_mark']]);
			}
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->is_print = SystemOrder::IS_PRINT;
    		$this->print_name = get_normal_options('print_name');
    	}  		
    	$this->fetch('batch_print');   	 	      
    }
    
    /**
     * 画手
     * @auth true
     */
    public function painter()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();	
			$ids = explode(',',$data['ids']);
			unset($data['ids']);
			if(!$data['painter_name']){
    			unset($data['painter_name']);
    		}
    		if(!$data['send_painter_at']){
    			unset($data['send_painter_at']);
    		}
			Db::name($this->table)->where(['id'=>$ids])->update($data);
			$this->success('保存成功');
    	}else{
    		$this->ids = $this->request->param('id');		
    		$this->painter = [1=>'无需画手',2=>'未发画手',3 => '已发画手',6 => '画手已发压缩包',7 =>'画手已返图已发客户确认',8 => '画手已返图已发客户确认，客户要求修改'];
    		$this->painter_name = get_normal_options('painter_name');
    	}  		
    	$this->fetch('painter');   	 	      
    }
    
    
    public function upload()
    {
        $image = request()->file('image');
        
        $uptype = sysconf('storage_type');
        if(in_array($uptype,['oss', 'qiniu', 'cos'])){
        	if (!$image->checkSize(3145728)) {
	        	$this->error('文件过大，不能大于3M');
	        }
        	$extend = pathinfo($image->getInfo('name'), PATHINFO_EXTENSION);     
        	
        	if(!in_array($extend,['jpg', 'jpeg', 'png'])){
        		$this->error('文件格式错误，只允许上传png，jpg，jpeg');
        	}       
	        $name = File::name($image->getPathname(), $extend, '', 'md5_file');     	
        	$name = explode('/',$name);
			$name = $name[1];
			$name = 'imgs/'.date('Ymd').'/'.$name;
			$info = File::instance($uptype)->save($name, file_get_contents($image->getRealPath()), false);
			if (is_array($info) && isset($info['url'])) {
	            $this->success('',$info['url']);
	       } else {
	            // 上传失败获取错误信息
	            $this->error('文件处理失败，请稍候再试！');
	        }
        }else{
        	$info = $image->move('upload');
	        if ($info) {
	            $this->success('',str_replace('\\','/','/upload/'.$info->getSaveName()));
	        } else {
	            // 上传失败获取错误信息
	            $this->error($image->getError());
	        }
        }
    }
    
    
    /**
     * 导出
     * @auth true
     */
    public function export()
    {  	
    	$data = $this->request->param();
    	$ids = explode(',', $data['id']);
    	$list = OrderService::export_order_label($ids);
    	toexcel($list['filename'],$list['titles'],$list['list']);   	 	      
    }
    
    
    /**
     * 导出排单
     * @auth true
     */
    public function export_make_plan()
    {  	
    	$data = $this->request->param();
    	$ids = explode(',', $data['id']);
    	$list = OrderService::export_order_make_plan($ids);
	    toexcelimg($list['filename'],$list['titles'],$list['list']);
    }
    

}
